//index.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
const lbbService = require('../service/service.js')

Page({
  data: {
    equipCode: '',
    hospitalId: '',
    hospitalName: '',
    equipInfo: {},
    fridModalShow: false,
    rfidCode: '',
  },
  onLoad: function (options) {
    let that = this
    console.log("options", options)
    that.setData({
      equipCode: options.equipCode,
      hospitalId: options.hospitalId,
      hospitalName: options.hospitalName,
      status: options.status
    })
    lbbService.queryEquipByRfid({ equId: parseInt(that.data.equipCode.replace(/[^0-9]/ig,"")) }, function (res) {
      that.setData({
        equipInfo: res
      })
    })
  },
  onReady: function () {
    this.toast = this.selectComponent("#toast")
    this.personalModal = this.selectComponent("#personalModal")
  },
  onShow: function () {

  },
  //标记丢失
  showLostTagModal: function () {
    let that = this
    let modalText = '确定将' + that.data.equipCode + '标记为丢失吗？'
    that.personalModal.showModal(modalText, that.lostTag)
  },
  lostTag: function() {
    let that = this
    lbbService.updateEquStat({
        equId: parseInt(that.data.equipCode.replace(/[^0-9]/ig,"")),
        nowStat: 10,
        lbmid: parseInt(that.data.hospitalId)
      },function(res){
        wx.showToast({
          title: '已标记丢失'
        })
        setTimeout(function(){
          wx.redirectTo({
            url: '/pages/startPatrol/startPatrol',
          })
        },1500)
      })
  },
  //标记未丢失
  showRemoveLostTagModal: function () {
    let that = this
    let modalText = '确定将' + that.data.equipCode + '标记未丢失吗？'
    that.personalModal.showModal(modalText, that.removeLostTag)
  },
  removeLostTag: function(e) {
    let that = this
    lbbService.updateEquStat({
      equId: parseInt(that.data.equipCode.replace(/[^0-9]/ig,"")),
      nowStat: 1,
      lbmid: parseInt(that.data.hospitalId)
    }, function (res) {
      wx.showToast({
        title: '已标记未丢失'
      })
      setTimeout(function () {
        wx.redirectTo({
          url: '/pages/startPatrol/startPatrol',
        })
      }, 1500)
    })
  },
})